<?php
/**
 *
 * @author fanzhanao
 * @version 
 */
class cartoon_model_subscribe extends cartoon_model_bmodel {
	public function __construct(){
    	parent::__construct();
        $this->table = 'cartoon_subscribe';
    }
    /**
     * 添加订阅
     *
     * @param unknown_type $cartoon_id
     * @param unknown_type $uid
     */
    public function add($cartoon_id,$uid){
    	if(!($cartoon_id && $uid )) return false;
    	if($this->has($cartoon_id,$uid)) return Error::ERROR_RECORD_EXISTS ;
    	$args['uid']	=	$uid;
    	$args['cartoon_id']	=	$cartoon_id;
    	$args['add_time']	=	CURRENT_TIME;
    	if($this->db->insert($this->table,$args)){
		member_util_interface::getUserCount($uid,true);
		return true;
	}
	else  return false;
    }
    
    /**
     * 取消订阅
     *
     * @param unknown_type $cartoon_id
     * @param unknown_type $uid
     */
    public function cancel($cartoon_id,$uid){
    	if(!($cartoon_id && $uid )) return false;
    	if($this->db->query("DELETE FROM $this->table WHERE uid=$uid AND cartoon_id = $cartoon_id ")){
		member_util_interface::getUserCount($uid,true);
		return true;
	}
 	else	return false;
    }
    
    public function has($cartoon_id,$uid){
    	$sql = "SELECT id FROM $this->table WHERE uid = $uid AND cartoon_id = $cartoon_id";
    	$rs = $this->db->fetchField($sql,'id');
    	return $rs?true:false;
    }
}
